import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n  = in.nextInt();
        in.nextLine();
        int[] nums = new int[n];
        int sum  = 0;
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
            sum += nums[i];
        }
        long pathSum = 0;
        long min = 0x3f3f3f3f;
        for (int i = 0; i < n-1; i++) {
            pathSum += nums[i];
            min = Math.min(min, pathSum * (sum-pathSum));
        }
        System.out.println(min);
    }
}
